/*
 *  Copyright (C) 2015, All Rights Reserved.
 */
package models.uuid;

import java.util.UUID;

/**
 * UUID工具.
 */
public class UUIDUtil {

    /**
     * 将随机UUID转换成32位字符串.
     */
    public static String getUUID32() {
        return UUID.randomUUID().toString().replaceAll("-", "");
    }

    /**
     * 将随机UUID转换成22位字符串.
     *
     * 短UUID, 只包含0-9a-zA-Z URL Safe Char.
     */
    public static String getUUID22() {
        UUID uuid = UUID.randomUUID();
        return Base58.compressedUUID(uuid);
    }


    /**
     * 将随机UUID转换成8位小写字符串.
     *
     * 短UUID, 只包含0-9a-z URL Safe Char.
     */
    public static String getShortId8() {
        UUID uuid = UUID.randomUUID();
        return Base58.compressedUUID(uuid).substring(12, 20).toLowerCase();
    }

    public static void main(String[] args) {
        System.out.println(getUUID22());
        System.out.println(getShortId8());
    }

}
